package com.woniuxy.service.ime;

import com.woniuxy.entity.Order;

import com.woniuxy.service.OrderService;


public class OrderServiceImpl implements OrderService {
    /**
     * 创建订单
     *
     * @param cartid    购物车id
     * @param addressid 收货地址id
     * @param paytype   支付类型
     * @return 创建好的Order
     */
    @Override
    public Order addOrder(Integer[] cartid, int addressid, String paytype) {
        return null;
    }
//public static CartService cartService = new CartServiceIme();
//public static AddressService addressService = new AddressServiceImpl();
//public static CartDao cartDao = new CartDaoIme();
//public static OrderDao orderDao = new OrderDaoImpl();
//public static OrderItemDao orderItemDao = new OrderItemDaoImpl();
//    @Override
//    public Order addOrder(Integer[] cartid, int addressid, String paytype) {
//        //获取根据id好获取购物车
//        List<Cart> carts = cartService.findCartsByIds(cartid);
//        //根据地址id获取Address
//        Address address = addressService.findAddressById(addressid);
//       //生成订单编号
//        Date date = new Date();
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
//        String date1 = simpleDateFormat.format(date);
//        StringBuilder sb = new StringBuilder();
//       sb.append("WN");
//       sb.append(date1);
//       Random r = new Random();
//       int date2 = r.nextInt(9000)+1000;
//       sb.append(date2);
//       //获取用户id
//       int userid = carts.get(0).getUserid();
//        //遍历总金额
//        double totalMoney = 0d;
//        for(Cart cart:carts){
//            totalMoney+=cart.getNums()* cart.getPrice();
//        }
//        Order order = new Order();
//        order.setOrderno(sb.toString());
//        order.setUserid(userid);
//        order.setOrdertime(new Date());
//        order.setAccept(address.getAccept());
//        order.setTelphone(address.getTelphone());
//        order.setAddress(address.getProvince()+address.getCity()+address.getArea()+address.getAddress());
//        order.setMoney(totalMoney);
//        order.setStatus("1");
//        order.setIsdel("1");
//        order.setPaytype(paytype);
//        boolean isSuucess = orderDao.addOrder(order);
//        if(isSuucess) {
//            for (Cart cart : carts) {
//                OrderItem orderItem = new OrderItem();
//                orderItem.setOrderid(order.getId());
//                orderItem.setGoods(cart.getGoods());
//                orderItem.setNums(cart.getNums());
//                orderItem.setPrice(cart.getPrice());
//                orderItem.setNums(cart.getNums());
//                //添加订单条目
//                orderItemDao.addOrderItem(orderItem);
//                //删除购物车
//                cartDao.delete(cart.getId());
//            }
//        }
//        return order;
//    }
}
